package com.jz.thread;

import java.lang.reflect.Method;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Test {
	public static void main(String[] args) throws InstantiationException, IllegalAccessException {

		Executor executor = new ThreadPoolExecutor(30, 80, 100, TimeUnit.MILLISECONDS, new DelayQueue());
		MyThread my = new MyThread();
		my.setDelayQueue(new DelayQueue<Task>());
		my.setExecutor(executor);

		Task t1 = new Task(1000);
		Task t2 = new Task(3000);
		Task t3 = new Task(8000);
		Task t4 = null;
		Object o;
		try {
			o = Class.forName("com.jz.thread.TestMethod").newInstance();
			Class[] param = { String.class };
			Method m = Class.forName("com.jz.thread.TestMethod").getMethod("testMethod", param);
			t4 = new MethodTask(10000, new Object[] { "1111" }, o, m);
		} catch (SecurityException e) {
			e.printStackTrace();
		} catch (NoSuchMethodException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

		Thread t = new Thread(my);
		t.setName("mythread");
		t.start();

		my.addTask(t4);
		my.addTask(t3);
		my.addTask(t2);
		my.addTask(t1);

	}

}
